#include "include/bt2.h"
/*! \file bt2.cpp
 * \brief Basic tutorial about light, shadow and camera
 *
 * This is the second tutorial from Ogre wiki. You will learn about different
 * types of shadows, creating cameras, and setting different lights on the 
 * scene.
 */
 

bt2::bt2(void)
{
}

bt2::~bt2(void)
{
}

void bt2::createCamera(void)
{
    /*! \fun createCamera()  
     * Create the camera, with the name PlayerCamera
     */
    mCamera = mSceneMgr->createCamera("PlayerCamera");
    mCamera->setPosition(Ogre::Vector3(0,10,500));
    /*! fun lookAt()
     *  lookAt is a nifty function, which makes our camera to "stare" at one point
     */
    mCamera->lookAt(Ogre::Vector3(0,0,0));
    
     /*! \fun setNearClipDistance
     * \brief Near clipping distance
     *
     * The clipping distance of a Camera specifies how close or far something 
     * can be before you no longer see it. Setting the near clipping distance 
     * makes it easier to see through Entities on the screen when you are very 
     * close to them. The alternative is being so close to an object that it 
     * fills the screen and you can't see anything but a tiny portion of it. You
     * can also set the far clipping distance as well. This will stop the engine 
     * from rendering anything farther away than the given value. This is 
     * primarily used to increase the framerate if you are rendering large 
     * amounts of things on the screen for very long distances.
     */
    mCamera->setNearClipDistance(19);
    mCameraMan = new OgreBites::SdkCameraMan(mCamera);
}

void bt2::createViewports(void)
{
    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
    mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth())/Ogre::Real(vp->getActualHeight()));
    //! setting here the aspect ration, just in case
}

void bt2::createScene(void)
{
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0,0,0)); //!< No color from the ambient
    mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); //!< The type of shadow:
    
    Ogre::Entity* entHero = mSceneMgr->createEntity("Ninja", "ninja.mesh");
    entHero->setCastShadows(true);
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entHero);

    Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
    Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
    Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity", "ground");
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround);
    entGround->setMaterialName("Examples");
    entGround->setCastShadows(false);
    //erase down
    Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
    pointLight->setType(Ogre::Light::LT_POINT);
    pointLight->setPosition(Ogre::Vector3(0, 150, 250));
    pointLight->setDiffuseColour(1.0, 0.0, 0.0);
    pointLight->setSpecularColour(1.0, 0.0, 0.0);
    Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight");
    directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
    directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0));
    directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0));
    directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 ));
    Ogre::Light* spotLight = mSceneMgr->createLight("spotLight");
    spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
    spotLight->setDiffuseColour(0, 0, 1.0);
    spotLight->setSpecularColour(0, 0, 1.0);
    spotLight->setDirection(-1, -1, 0);
    spotLight->setPosition(Ogre::Vector3(300, 300, 0));
    spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));
}

